<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数柯里化</title>
</head>

<body>
<!-- 创建test -->
<div id="test"></div>
<!-- 引入核心库 -->
<script src="../js/react.development.js"></script>
<!-- 引入react操作DOM支持库 -->
<script src="../js/react-dom.development.js"></script>
<!-- 引入babel 用于将jsx转为js -->
<script src="../js/babel.min.js"></script>
<!-- 引入prop-types 用于对组件标签属性进行限制 -->
<script src="../js/prop-types.js"></script>
<script type="text/babel">  // 此处引入一定要写babel
class Login extends React.Component {
  state = {
    userName: "",
    password: ""
  }

  render() {
    return (
      <form action="http://www.baidu.com" onSubmit={this.handleSubmit}>
        用户名：
        <label>
          <input type="text" placeholder="账户" name="userName" onChange={ this.saveFormData("userName")}/>
        </label>
        密码：
        <label>
          密码：
          <input type="password" placeholder="密码" name="password" onChange={this.saveFormData("password")}/>
        </label>
        <button>提交</button>
      </form>
    )
  }

  saveFormData = (dataType) => {
    //  保存账号和密码的事件
    return (e) => {
     this.setState({ [dataType]: e.target.value })
    }
  }
  handleSubmit = (e) => {
    e.preventDefault();
    const {userName, password} = this.state;
    alert(`账号是${userName},密码是 ${password}`)
  }
}

ReactDOM.render(<Login/>, document.getElementById("test"))
</script>
</body>

</html>